/**
 * 
 */
package cn.edu.nju.ws.sview.wyge.relations.adataset.comment;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import cn.edu.nju.ws.sview.database.DBConnectionFactory;
import cn.edu.nju.ws.sview.wyge.relations.datasets.DatasetItem;

/**
 * @author Weiyi Ge (geweiyi@gmail.com) 2012-7-24
 * 
 */
public class AllComments {
	public static int getCommentNum(String ds_type, int ds_id)
			throws SQLException {
		int num = 0;
		Connection con = DBConnectionFactory.getConnection();
		PreparedStatement selps = con
				.prepareStatement("SELECT count(*) FROM ds_comment where ds_type = ? and ds_id = ?");
		selps.setString(1, ds_type);
		selps.setInt(2, ds_id);
		ResultSet selrs = selps.executeQuery();
		if (selrs.next()) {
			num = selrs.getInt(1);
		}
		selrs.close();
		con.close();
		return num;
	}
	
	public static ArrayList<DatasetComment> fetchAll(int start, int length, //String lang, 
			String ds_type, int ds_id) {
//		return DatasetComment.getCommentsByDatasetLangUserOrderByScore(ds_type, ds_id, lang, null, start, length);
//		return DatasetComment.getCommentsByDatasetLangUserOrderByTime(ds_type, ds_id, lang, null, start, length);
		//return DatasetComment.getDescriptions(ds_type, ds_id, start, length);
		return new DatasetItem(ds_type, ds_id, null).getDescriptions(start, length);
	}
}
